package com.dq.domain.message.oneself.centre;

import com.alibaba.fastjson.JSONObject;
import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;

import com.dq.domain.message.oneself.InstructionMessage;
import com.dq.domain.message.oneself.Message;
import com.dq.domain.message.oneself.info.InstructionMessageReturn;
import com.dq.domain.sys.section.SysSection;
import com.dq.domain.sys.user.user.base.SysUser;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;

/**
 * @author cf
 */
@Data
@Entity
@ApiModel("指令消息员工关联")
public class InstructionStaffuserCentre extends BaseEntity implements VO.ToVO {

    @ApiModelProperty("门店")
    @ManyToOne
    public SysSection org;

    @ApiModelProperty("员工")
    @ManyToOne
    public SysUser staffUser;
    @ApiModelProperty("指令消息")
    @ManyToOne
    protected InstructionMessage instructionMessage;

    @ApiModelProperty("员工对指令进行回复")
    @ManyToOne
    public InstructionMessageReturn instructionMessageReturn;

    @ApiModelProperty("消息状态")
    @Enumerated(EnumType.ORDINAL)
    @NotNull
    protected Message.MessageStatus messageStatus = Message.MessageStatus.noSee;


    @Data
    @ApiModel("视图")
    public static class Vo implements VO {
        @ApiModelProperty("主题名称")
        public String theme;
        @ApiModelProperty("内容")
        protected String content;
        @ApiModelProperty(value = "指令开始时间",hidden = true)
        protected Long beginTimeRestrict;
        @ApiModelProperty(value = "指令结束时间",hidden = true)
        protected Long nedTimeRestrict;

        @ApiModelProperty("附件地址")
        public String annexUrl;
        @ApiModelProperty("图片地址")
        public String imageUrl;

        @ApiModelProperty("员工对指令进行回复")
        public JSONObject instructionMessageReturn;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();

        vo.theme = this.instructionMessage == null ? "" : this.instructionMessage.theme;
        vo.content = this.instructionMessage == null ? "" : this.instructionMessage.getContent();
        vo.beginTimeRestrict = this.instructionMessage == null ? null : this.instructionMessage.getBeginTimeRestrict();
        vo.nedTimeRestrict = this.instructionMessage == null ? null : this.instructionMessage.getNedTimeRestrict();

        vo.annexUrl = this.instructionMessage == null ? "" : this.instructionMessage.getAnnexUrl();
        vo.imageUrl = this.instructionMessage == null ? "" : this.instructionMessage.getImageUrl();

        if(this.instructionMessageReturn != null) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("annexUrl", instructionMessageReturn.getAnnexUrl());
            jsonObject.put("imageUrl", instructionMessageReturn.getImageUrl());
            jsonObject.put("remark", instructionMessageReturn.getRemark());
            vo.instructionMessageReturn = jsonObject;
        }

        return vo;
    }

}
